package com.mmall.utils;


import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class PropertiesUtil {

    private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);

    private static Properties properties;

    static {
        String filename =  "mmall.properties";
        properties = new Properties();
        try {
            properties.load(new InputStreamReader(Properties.class.getClassLoader()
                    .getResourceAsStream(filename),"utf-8"));
        } catch (IOException e1) {
            e1.printStackTrace();
            logger.error("日志加载错误");
        }
    }

    public static String getProperty(String key, String defaultVal) {
        String result = properties.getProperty(key, defaultVal);
        if(StringUtils.isBlank(result)){
            result = defaultVal;
        }
        return result;
    }

    public static String getProperty(String key){
        String result = properties.getProperty(key);
        if(StringUtils.isBlank(result)){
            return null;
        }
        return result;
    }
}
